{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ed2b0f36",
   "metadata": {},
   "source": [
    "## random 模块练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4e38e5ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.8067337130816913\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "print(random.random())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27316b9c",
   "metadata": {},
   "source": [
    "* 用于生成一个由0到1的随机符点数（可为小数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b3acf2a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print (random.randint(1,7)) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f62c014b",
   "metadata": {},
   "source": [
    "* 范围变成括号内整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f62e242c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This second seems a little odd.\n",
      "Not an odd second.\n",
      "Not an odd second.\n",
      "This second seems a little odd.\n",
      "Not an odd second.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9806466e",
   "metadata": {},
   "source": [
    "* 循环五次，随机（0，5）等待时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "71c3bcb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "35\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ccf2508",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
